package com.ldn.server.queue.config;

import com.ldn.common.basic.dispose.bo.MqttRocketmqBo;
import com.ldn.server.queue.covert.MqttEquipmentCovert;
import com.ldn.server.queue.covert.MqttMemberCovert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;

import java.util.function.Consumer;

/**
 * @author 李大牛家的牛 (scafel@163.com)
 * @product serverless
 * @className QueueBeanConfig
 * @createDate 2025/3/7 - 9:46
 * @description ToDo...
 **/
@Slf4j
@Configuration
public class QueueBeanConfig {


    @Bean
    public Consumer<Message<MqttRocketmqBo>> mqttMember() {
        return msg -> {
            try {
                MqttRocketmqBo payload = msg.getPayload();
                MqttMemberCovert covert = new MqttMemberCovert();
                // 解析并转化payload
                covert.transformPayload(payload);
            } catch (Exception e) {
                log.error("消息转换异常，原因：{ }", e);
            }
        };
    }

    @Bean
    public Consumer<Message<MqttRocketmqBo>> mqttEquipment() {
        return msg -> {
            MqttRocketmqBo payload = msg.getPayload();
            MqttEquipmentCovert covert = new MqttEquipmentCovert();
            // 解析并转化payload
            covert.transformPayload(payload);
        };
    }

}
